package com.itheima.controller;

import com.itheima.pojo.User;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 刘全
 * @date 2021/9/15
 */
@RestController// = controller + ResponseBody
//@Controller
public class UserController {

    //设置映射路径为/save，即外部访问路径
    @RequestMapping("/save")
    //设置当前操作返回结果为指定json数据（本质上是一个字符串信息）
    //@ResponseBody
    public String save() {
        System.out.println("user save ...");
        return "https://www.baidu.com";
    }

    @RequestMapping("/test1")
    public String test1(@RequestParam("name") String username, @RequestParam("age") int age) {
        System.out.println("user test1 ..." + username + "==" + age);
        return "success";
    }

    @RequestMapping("/test2")
    public String test2(@RequestBody List<User> list) {
        System.out.println("user test2 ..." + list);
        return "success";
    }

    @RequestMapping("/test3")
    public User test3(int id) {
        User u = new User();
        switch (id) {
            case 1:
                u.setName("张三");
                u.setAge(23);
                return u;
            case 2:
                u.setName("李四");
                u.setAge(24);
                return u;
            case 3:
                u.setName("王五");
                u.setAge(25);
                return u;
        }
        return null;
    }

    @GetMapping("/test4/{id}")
    public String test4(@PathVariable Integer id) {
        System.out.println("user test4 ..." + id);
        return "success";
    }
}
